<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>校园招聘管理系统</title>
		<link type="text/css" rel="stylesheet" href="css/backend.css" />
	</head>
	<!-- RecruitInfo的id从+20开始 -->
	<body onload="loadform()">
		<div class="container">
			<div class="wrapper">
				<div class="header" style="background-color: crimson;">
					企业端
				</div>
				<!-- log图片 -->
				<div class="log"><img src="img/company.jpg" style="width: 100%;"></div>
				<!-- 侧边栏 -->
				<div class="aside" style="background-color: #FF8C00;">
					<ul>
						<li>
							<a href="#" onclick="loadform()">首页</a>
						</li>

						<li>
							<a href="#" onclick="addNotes()">发布招聘信息 </a>
							<!-- <ul>
								<li><a href="#">子导航1</a></li>
								<li><a href="#">子导航2</a></li>
								<li><a href="#">子导航3</a></li>
							</ul> -->
						</li>

						<li>
							<a href="#" onclick="selectRecruitInfo()">查看学生简历信息</a>
						</li>


						<li>
							<a href="#" onclick="selectPushInfo()">查看学生投递通知</a>
						</li>
					</ul>
				</div>

				<!-- 主体部分 -->
				<div class="section">
					<div id="1" class="module">
						<img src="img/首页2.jpg" style="width: 60%; margin-left: 250px;margin-top: 100px;">

						<!-- 个人简历 :根据主键account(set,get),如果填写过就update方法,没填写过就save方法-->
					</div>
					<div id="2" class="module">


						<table border="1" width="100%">
							<tr>
								<th style="background-color: lightcyan;">职位</th>
								<th style="background-color: lightcyan;">工资</th>
								<th style="background-color: lightcyan;">需求</th>
								<th style="background-color: lightcyan;">地址</th>
								<th style="background-color: lightcyan;">专业</th>
							</tr>

							<form>
								<tr>

									<th>
										<input id="6" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="7" type="number" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="8" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="9" type="text" style="height: 40px;width: 100%" />
									</th>
									<th>
										<input id="10" type="text" style="height: 40px;width: 100%" />
									</th>


								</tr>


						</table>
						<div class="box1">
							<input class="btn" type="button" value="发布" style="float: left;margin-top: 10%;margin-left: 20%;" onclick="saveInfo()">
							<input class="btn" type="reset" value="重置" style="float: left;margin-left: 40%; margin-top:10% ;">
						</div>
						</form>
					</div>


					<!-- 查看学生信息  -->
					<div id="3" class="module">
						<div id="14" class="recruitInfoBox">
							<!-- <input type="button" onclick="createNewElements()" value="32322" /> -->
						</div>
					</div>





					<!-- 查看学生投递的通知-->
					<div id="4" class="module">
						<div id="15" class="recruitInfoBox" style="height: 550px;">

						</div>
						<!-- <input type="button" onclick="getTouDiStudentInfo()" value="下一条" class="btn" style="position: relative;left: 500px;" /> -->
					</div>
				</div>

			</div>
		</div>
	</body>

	<script src="./js/axios-0.18.0.js"></script>
	<script src="js/login.js"></script>
	<script language="JavaScript">
		var companyAccount = new Array;
		var account = sessionStorage.getItem("user");
		var accountHaveValue = "false"; //判断简历是否已经写过信息,决定是update还是save

		//请求url
		var locaUrl;
		setTimeout("getLocation()");
		function getLocation(){
			// 获取当前页面的完整 URL
			var currentUrl = window.location.href;
			// 提取网段部分
			var hostname = (new URL(currentUrl)).hostname;
			// 构建 Ajax 请求的 URL
			locaUrl = "http://" + hostname; //+ ":8080/recruitInfo";
		}
		//打开首页
		function loadform() {
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("1").classList.add("active");
		}

		//切换个人简历页面+loadNoteData(temp1)
		function addNotes() {
			if (account == "" || account == "null") {
				alert("系统错误,请重新登录");
				location = '/webapp/login.html';
				return;
			}
			var temp;
			var a = 0;
			loadNoteData();
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("2").classList.add("active");
		}
		//加载发布职位信息+addNotes
		function loadNoteData() {
			if (account == "" || account == "null") {
				alert("系统错误,请重新登录");
				location = '/webapp/login.html';
				return;
			}
			accountHaveValue = "false";

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruitInfo/' + account).then(result => {

				// alert(accountHaveValue);
				//传过来的值不为空,赋值
				//将获取到的JSON数组转换为JavaScript对象
				if (result.data.data.title != null){
					document.getElementById("6").value = result.data.data.title;
					document.getElementById("7").value = result.data.data.salary;
					document.getElementById("8").value = result.data.data.need;
					document.getElementById("9").value = result.data.data.address;
					document.getElementById("10").value = result.data.data.major;
					accountHaveValue = "true"; //已经写过简历,之后用修改不用save,因为主键
				}

			})
		}

		//保存发布的招聘信息
		function saveInfo() {
			if (account == "" || account == null) {
				alert("系统错误，请重新登陆");
				location = '/webapp/login.html';
				return;
			}
			var account1 = account;
			var title1 = document.getElementById("6").value;
			var salary1 = document.getElementById("7").value;
			var need1 = document.getElementById("8").value;
			var address1 = document.getElementById("9").value;
			var major1 = document.getElementById("10").value;

			if (title1 == "" || salary1 == "" || need1 == "" || major1 == "" || address1 == "") {
				alert("请不要有空值");
				return;
			} else if (accountHaveValue == "false") {
				const data = {
					account: account1,
					title: title1,
					salary: salary1,
					need: need1,
					address: address1,
					major: major1,
					post: "false"
				};
				axios.withCredentials = true;
				axios.post(locaUrl + ':8080/recruitInfoSave', data).then(result => {
					if (result.data.code == "1") {
						alert("已发布，等待管理员确认");
						accountHaveValue = "true";
					} else if (result.data.code == "0") {
						alert(result.data.msg);
					}
				});
			} else if (accountHaveValue == "true") {
				//update
				const data = {
					account: account1,
					title: title1,
					salary: salary1,
					need: need1,
					address: address1,
					major: major1,
					post: "false"
				};
				axios.withCredentials = true;
				axios.put(locaUrl + ':8080/recruitUpdate', data).then(result => {
					console.log(result);
					if (result.data.code == "1") {
						alert("操作成功,.等待管理员确认")
					} else if (result.data.code == "0") {
						alert(result.data.msg);
						alert("失败");
					}
				});
			}
		}

		//切换查看所有学生简历
		function selectRecruitInfo() {
			var userList = document.getElementById('14');
			userList.innerHTML = "";
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("3").classList.add("active");
			var recruitInfoBox = document.getElementById("14");

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/studentInfo').then(result => {
				for (var i = 0; i <= result.data.data.length; i++) {
					// var recruitInfo = document.createElement("p");
					var text = document.createTextNode("姓名:" + result.data.data[i].name);
					recruitInfoBox.appendChild(text); //将标题添加到页面



					var text = document.createTextNode("   " + "，年龄:" +result.data.data[i].age);
					recruitInfoBox.appendChild(text); //将标题添加到页面


					var text = document.createTextNode("   " + "，性别：" + result.data.data[i].sex);
					recruitInfoBox.appendChild(text); //将标题添加到页面



					var text = document.createTextNode("   " + "专业:" + result.data.data[i].major);
					recruitInfoBox.appendChild(text); //将标题添加到页面

					var text = document.createTextNode("   " + "电话:" + result.data.data[i].phone);
					recruitInfoBox.appendChild(text); //将标题添加到页面

					var text = document.createTextNode("   " + "邮箱:" +result.data.data[i].email);
					recruitInfoBox.appendChild(text); //将标题添加到页面

					var text = document.createTextNode("   " + "个人简介:" + result.data.data[i].introduction);
					recruitInfoBox.appendChild(text); //将标题添加到页面

					var text = document.createTextNode("   " + "曾获奖励:" + result.data.data[i].reward);
					recruitInfoBox.appendChild(text); //将标题添加到页面

					var button1 = document.createElement("input");
					button1.type = "button";
					button1.value = "邀请";
					button1.name = result.data.data[i].account; //将账户传给按钮的name
					button1.setAttribute("onclick", "yaoQingStudent(name)"); //事件用这个
					var link2 = document.createElement("br"); //换行一下
					recruitInfoBox.appendChild(link2); //将标题添加到页面
					recruitInfoBox.appendChild(button1);

					var link2 = document.createElement("hr"); //分隔一下
					recruitInfoBox.appendChild(link2);

				}
			})

		}

		//邀请学生 用yaoqing表,name是学生账号
		function yaoQingStudent(name) {
			var shifouyaoqingguo = "false";
			// alert(name);
			var ac = name;//学生
			var acs = account;//公司
			if (account == "" || account == null) {
				alert("系统错误，请重新登陆");
				location = '/webapp/login.html';
				return;
			}
			<!-- 查看投递信息:查找表company_student,如果stu账号匹配就返回company账号,根据company账号返回招聘信息,已投递的,根据true和false判断是否要面试 -->
			//发送数据给company_student表

			const data = {
				accountCm: account,
				accountStu: ac,
				yaoqing: "false"
			};
			axios.withCredentials = true;
			axios.post(locaUrl+':8080/yaoQing',data).then(result => {
				if (result.data.code == "1") {
					alert("邀请成功，等待回复");
					shifouyaoqingguo = "true";
					var a = document.getElementsByName(name);
					a[0].value = "已邀请";
				}else if(result.data.code == "0") {
					alert(result.data.msg);
				}
			});
		}

		var accountStudent = new Array; //company_student表里的数据
		//切换查看学生投递过来的通知,根据commany_student表,查找contain了 本公司账号 的学生账户  查看学生是否投递了本公司,加个接收简历的按钮
		function selectPushInfo() {
			var recruitInfoBox = document.getElementById("15");
			recruitInfoBox.innerHTML = "";
			var a = new Array;
			if (account == "" || account == "null") {
				alert("系统错误,请重新登录");
				location = '/webapp/login.html';
				return;
			}
			var accountCm = account;
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("4").classList.add("active");

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruit/' + accountCm).then(result => {
				accountStudent = result.data.data;
				getTouDiStudentInfo();
			})

		}
		var count = 0;
		// 获取投递过来的学生信息 根据accountStudent
		function getTouDiStudentInfo() {
			var recruitInfoBox = document.getElementById("15");
			var a = accountStudent.length;
			// alert(accountStudent[count].accountStu);
			var account1 = accountStudent[count].accountStu;

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/student/' + account1).then(result => {
				var text = document.createTextNode("姓名:" + result.data.data.name);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + "，年龄:" + result.data.data.age);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + "，性别：" + result.data.data.sex);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + ",专业:" + result.data.data.major);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + ",电话:" + result.data.data.phone);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + ",邮箱:" + result.data.data.email);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + ",个人简介:" + result.data.data.introduction);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var text = document.createTextNode("   " + ",曾获奖励:" + result.data.data.reward);
				recruitInfoBox.appendChild(text); //将标题添加到页面

				var button1 = document.createElement("input");
				button1.type = "button";
				button1.value = "同意";
				button1.name = result.data.data.account; //将账户传给按钮的name
				button1.setAttribute("onclick", "agree(name)"); //事件用这个
				var link2 = document.createElement("br"); //换行一下
				recruitInfoBox.appendChild(link2); //将标题添加到页面
				recruitInfoBox.appendChild(button1);

				var link2 = document.createElement("hr"); //分隔一下
				recruitInfoBox.appendChild(link2);

			})
			count++;
			if (count == accountStudent.length) {
				count = 0;
				return; //到头就退出
			}
			setTimeout("getTouDiStudentInfo()", 1000);
		}

		//同意学生来面试,把company_student的whether改true就是同意
		function agree(name) {
			//name是学生账号
			alert(name);
			var ac = name; //学生账号
			var acs = account; //公司账号
			var temp = ac + acs;
			if (account == "" || account == null) {
				alert("系统错误，请重新登陆");
				location = '/webapp/login.html';
				return;
			}
			//发送数据给company_student表
			// 创建XMLHttpRequest对象

			//update
			const data = {
				whether:"true"
			};
			axios.withCredentials = true;
			axios.put(locaUrl+':8080/Company_StudentUpdate/' + acs+'/'+ac,data).then(result => {
				if (result.data.code == "1") {
					alert("同意成功");
					var a = document.getElementsByName(name);
					a[0].value = "已同意";
				}else if(result.data.code == "0") {
					alert(result.data.msg);
				}
			});
		}

		// var t = 0;
		// var t2 = 0;

		// function aa() {
		// 	var userList = document.getElementById('15');
		// 	userList.innerHTML = "";
		// 	alert("第" + (t + 1) + "条");


		// 	var xmlHttpRequest1 = new XMLHttpRequest();
		// 	//2. 发送异步请求
		// 	xmlHttpRequest1.open('GET', locaUrl+':8080/recruitInfo/' + accountCompany[t].accountCm);
		// 	xmlHttpRequest1.send(); //发送请求
		// 	var recruitInfoBox = document.getElementById("15");
		// 	//3. 获取服务响应数据
		// 	xmlHttpRequest1.onreadystatechange = function() {
		// 		// 将获取到的JSON数组转换为JavaScript对象
		// 		var jsonArray = JSON.parse(xmlHttpRequest1.responseText);
		// 		if (xmlHttpRequest1.readyState === 4 && xmlHttpRequest1.status === 200) {
		// 			console.log(xmlHttpRequest1.responseText);

		// 			// // var recruitInfo = document.createElement("p");
		// 			var text = document.createTextNode("招聘职位:" + jsonArray[0].title);
		// 			recruitInfoBox.appendChild(text); //将标题添加到页面
		// 			console.log(t);


		// 			var text = document.createTextNode("   " + "工资:" + jsonArray[0].salary);
		// 			recruitInfoBox.appendChild(text); //将标题添加到页面


		// 			var text = document.createTextNode("   " + "入职需求" + jsonArray[0].salary);
		// 			recruitInfoBox.appendChild(text); //将标题添加到页面



		// 			var text = document.createTextNode("   " + "公司地址:" + jsonArray[0].salary);
		// 			recruitInfoBox.appendChild(text); //将标题添加到页面

		// 		}

		// 	}

		// 	if (accountCompany.length - 1 == t) {
		// 		t = -1;
		// 	} {
		// 		t++;
		// 	}
		// }
	</script>


</html>
